﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Signage01.util
{
    public static class RssUtil
    {        

        public static string geturl(this RSSSource rssSource)
        {
            string urlPrepend = "http://rss.news.yahoo.com/rss/";
            switch (rssSource)
            {
                case RSSSource.YAHOO_TOP_STORIES:
                    return urlPrepend + "topstories";
                case RSSSource.YAHOO_US_NATIONAL:
                    return urlPrepend + "us";
                case RSSSource.YAHOO_ELECTIONS:
                    return urlPrepend + "elections";
                case RSSSource.YAHOO_TERRORISM:
                    return urlPrepend + "terrorism";
                case RSSSource.YAHOO_WORLD:
                    return urlPrepend + "world";
                case RSSSource.YAHOO_MIDEAST_CONFLICT:
                    return urlPrepend + "mideast";
                case RSSSource.YAHOO_POLITICS:
                    return urlPrepend + "politics";
                case RSSSource.YAHOO_BUSINESS:
                    return urlPrepend + "business";
                case RSSSource.YAHOO_SPORTS:
                    return urlPrepend + "sports";
                case RSSSource.YAHOO_TECHNOLOGY:
                    return urlPrepend + "tech";
                case RSSSource.YAHOO_SCIENCE:
                    return urlPrepend + "science";
                case RSSSource.YAHOO_MOST_EMAILED:
                    return urlPrepend + "mostemailed";
                case RSSSource.YAHOO_MOST_VIEWED:
                    return urlPrepend + "mostviewed";
                case RSSSource.YAHOO_MOST_RECOMMENDED:
                    return urlPrepend + "highestrated";
                default:
                    return null;
            }
        }

        public static string getTitle(this RSSSource rssSource)
        {
            switch (rssSource)
            {
                case RSSSource.YAHOO_TOP_STORIES:
                    return "Top stories";
                case RSSSource.YAHOO_US_NATIONAL:
                    return "US National";
                case RSSSource.YAHOO_ELECTIONS:
                    return "Elections";
                case RSSSource.YAHOO_TERRORISM:
                    return "Terrorism";
                case RSSSource.YAHOO_WORLD:
                    return "World";
                case RSSSource.YAHOO_MIDEAST_CONFLICT:
                    return "Mideast Conflict";
                case RSSSource.YAHOO_POLITICS:
                    return "Politics";
                case RSSSource.YAHOO_BUSINESS:
                    return "Business";
                case RSSSource.YAHOO_SPORTS:
                    return "Sports";
                case RSSSource.YAHOO_TECHNOLOGY:
                    return "Technology";
                case RSSSource.YAHOO_SCIENCE:
                    return "Science";
                case RSSSource.YAHOO_MOST_EMAILED:
                    return "Most Emailed";
                case RSSSource.YAHOO_MOST_VIEWED:
                    return "Most Viewed";
                case RSSSource.YAHOO_MOST_RECOMMENDED:
                    return "Most Recommended";
                default:
                    return null;
            }
        }

        public static List<string> getAllTitles()
        {
            var rssItems = Enum.GetValues(typeof(RSSSource));
            List<string> listAllTitles = new List<string>();

            foreach (RSSSource source in rssItems)
            {
                string temp = getTitle(source);
                listAllTitles.Add(temp);
            }

            return listAllTitles;
        }

        public static string getAllTitlesCombined(RSSSource rssSource)
        {
            string strCombined = "";

            string urlRSS = geturl(rssSource);

            RssReader rssReader = new RssReader(urlRSS);

            List<string> newsTitles = rssReader.getNewsTitles();


            foreach (string newsTitle in newsTitles)
            {
                strCombined = strCombined + newsTitle + "   -   ";
            }

            return strCombined;

        }


        /*
        public static RSSSource getEnumFromString(string strRss)
        {
            RSSSource.
        }
        */
    }
}
